﻿using OpenGLES;

namespace PFD
{
    public class GeometricTransformation : IArrayElementModifier<float>
    {
        public enum TransformationType
        {
            Translation,
            Rotation,
            Scale
        }

        public TransformationType type;
        public GeometryArray info;

        public GeometricTransformation(TransformationType t)
        {
            info = new GeometryArray();

            type = t;
            if (t == TransformationType.Rotation)
                info.array = new float[4];
            else
                info.array = new float[3];
        }

        #region IArrayElementModifier<float> Members

        public bool IsDirty { get { return info.IsDirty; } }
        public void ResetDirtyFlag() { info.ResetDirtyFlag(); }

        public float this[long nNumber]
        {
            get
            {
                return info[nNumber];
            }
            set
            {
                info[nNumber] = value;
            }
        }

        #endregion

        public void ApplyTransform(IRenderDevice rd)
        {
            switch (type)
            {
                case TransformationType.Translation:
                    rd.TranslateObject(info[0], info[1], info[2]);
                    break;

                case TransformationType.Rotation:
                    rd.RotateObject(info[0], info[1], info[2], info[3]);
                    break;

                case TransformationType.Scale:
                    rd.ScaleObject(info[0], info[1], info[2]);
                    break;
            }
        }
    }
}
